#include "bs_common.h"

uint64_t atou64(const char* str){
    uint64_t    value = 0;
    uint64_t    factor = 1;
    int         i = 0;
    int         len = strlen(str);

    if(len == 0){
        return 0;
    }

    for(i=len-1; i>=0; i--){
        if(bs_is_num(str[i])){
            factor = factor*10;
            value += (str[i]-'0')*(factor/10);
        }
        else{
            return -1;
        }
    }

    return value;
}

state_t convert(const char *fromset, const char *toset, char *from,size_t from_len, char *to,size_t to_len)
{
    iconv_t cd;
    cd=iconv_open(toset,fromset);
    if(iconv(cd, &from, &from_len, &to, &to_len)==-1){
        iconv_close(cd);
        return BS_INVALID;
    }

    iconv_close(cd);
    return BS_SUCCESS;
}
